package com.sziit.se.highconcurrency.common.constant;

import lombok.Getter;

@Getter
public enum HttpResponseCodeEnums {

    SUCCESS(200, "成功"),
    ERROR(500, "系统异常"),
    UNAUTHORIZED(401, "认证失败"),
    FORBIDDEN(403, "无权限"),
    NOT_FOUND(404, "资源不存在"),
    METHOD_NOT_ALLOWED(405, "请求方法不支持"),
    UNSUPPORTED_MEDIA_TYPE(415, "不支持的媒体类型"),
    TOO_MANY_REQUESTS(429, "请求过于频繁"),
    INTERNAL_SERVER_ERROR(500, "服务器内部错误"),
    BAD_GATEWAY(502, "网关错误"),
    SERVICE_UNAVAILABLE(503, "服务不可用"),
    GATEWAY_TIMEOUT(504, "网关超时"),
            ;

    private final int code;
    private final String message;

    HttpResponseCodeEnums(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public static HttpResponseCodeEnums findByCode(int code) {
        HttpResponseCodeEnums[] values = values();
        for (HttpResponseCodeEnums value : values) {
            if (value.getCode() == code) {
                return value;
            }
        }
        return null;
    }
}
